package com.serverA.service;

import com.serverA.entity.User;
import com.serverA.feign.ServerBClient;
import com.serverA.feign.ServerCClient;
import com.serverA.mapper.UserMapper;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: wbk
 * @Date: 2024/3/1  14:57
 * @Description:
 */
@Service
@Slf4j
public class UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ServerCClient serverCClient;
    @Autowired
    private ServerBClient serverBClient;

    @GlobalTransactional
    public void add(){
        log.info("Seata全局事务id=================>{}", RootContext.getXID());
        userMapper.insert(new User().setAge(11)
                .setName("user_a")
                .setCode("11"));
        serverBClient.add();
        serverCClient.add();
    }
}
